package com.woniuxy.ams.service.impl;

import com.woniuxy.ams.dao.CompanyTemplate2AssessItemDao;
import com.woniuxy.ams.entity.AssessItem;
import com.woniuxy.ams.entity.CompanyTemplate;
import com.woniuxy.ams.entity.CompanyTemplate2AssessItem;
import com.woniuxy.ams.service.ICompanyTemplate2AssessItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公司模板对应考核计划service层
 */
@Service
public class CompanyTemplate2AssessItemServiceImpl implements ICompanyTemplate2AssessItemService {

    /**
     * 注入dao
     */
    @Resource
    CompanyTemplate2AssessItemDao companyTemplate2AssessItemDao;

    /**
     * 新增模板对应考核计划
     * @param template2AssessItems
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int addTemplate2AssessItem(List<CompanyTemplate2AssessItem> template2AssessItems) {
        return companyTemplate2AssessItemDao.addTemplate2AssessItem(template2AssessItems);
    }

    /**
     * 查询所有模板对应考核计划
     * @return List<CompanyTemplate2AssessItem>
     */
    @Override
    public List<CompanyTemplate2AssessItem> findAllTemplate2AssessItem() {
        return companyTemplate2AssessItemDao.findAllTemplate2AssessItem();
    }

    /**
     * 更改模板对应考核计划
     * @param companyTemplate
     * @param assessItems
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int updateTemplate2AssessItem(CompanyTemplate companyTemplate, List<AssessItem> assessItems) {
        return companyTemplate2AssessItemDao.updateTemplate2AssessItem(companyTemplate, assessItems);
    }

    /**
     * 根据模板删除模板对应考核计划
     * @param companyTemplate
     * @return int
     */
    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int deleteTemplate2AssessItem(CompanyTemplate companyTemplate) {
        return companyTemplate2AssessItemDao.deleteTemplate2AssessItem(companyTemplate);
    }
}
